package com

import (
	"encoding/json"
)

func PrintStruct(obj interface{}) (ret string) {

	defer func() {
		if err := recover(); err != nil {
			ret = "not support value type! must Struct"
		}
	}()

	m := StructToMap(obj)

	jsonStr, err := json.Marshal(m)

	if err != nil {
		ret = "parse err!"
	}

	ret = string(jsonStr)

	return ret
}

func TplMkSlice(args ...interface{}) []interface{} {
	return args
}

func TplAddToMap(args ...interface{}) string {
	if len(args) != 3 {
		panic("TplAddToMap must 3 params")
	}

	mapVar, mapOk := args[0].(map[interface{}]interface{})
	if !mapOk {
		panic("TplAddToMap first param must be map[interface{}]interface{}")
	}

	keyVar, keyOk := args[1].(string)

	if !keyOk {
		panic("TplAddToMap second param must be string")
	}

	mapVar[keyVar] = args[2]

	return ""
}
